const Controller = require('../../core/controller/ApiController');
const {Route, HttpGet, HttpPost, Middleware, filters} = require('../../../plugin/egg-decorator-router/lib');
const {ExceptionHandler} = require('../../../plugin/egg-controller-exception-handler/lib');

@Route('/api/admin')
class AdminController extends Controller {

    @HttpPost('/login')
    @ExceptionHandler()
    async login() {
        const rule = {
            account: 'string',
            pwd: 'string',
            remember: 'int'
        };
        const body = this.ctx.request.body;
        this.validate(rule, body);
        this.result.data = await this.service.admin.admin.main.login(body.account, body.pwd, body.remember);
        return '登录成功'
    }


    //教工登录
    @HttpPost('/staffLogin')
    async staffLogin(){
        const rule = {
            staff_number:'string',
            staff_password:'string',

        };
        this.validate(rule, this.ctx.request.body);
        this.result.data = await this.service.admin.admin.main.staffLogin(this.ctx.request.body.account, body.pwd, body.remember);
        return '登录成功'

    }
    //退出登录
    @HttpPost('/logout')
    @ExceptionHandler()
    async logout() {
        await this.service.admin.admin.main.logout();
        return '退出成功'
    }

}

module.exports = AdminController;
